// Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Project: chat.spboucher.ai // "Stop" aborts the upstream OpenRouter stream — never fake cancellation. import { NextResponse, type NextRequest } from "next/server"; import { requireSession } from "@/lib/auth/guard"; import { cancelGeneration, generationState } from "@/lib/generate"; export const runtime = "nodejs"; type Params = { params: Promise<{ id: string }> }; export async function POST(_req: NextRequest, { params }: Params) { const { unauthorized } = await requireSession(); if (unauthorized) return unauthorized; const { id } = await params; const cancelled = cancelGeneration(id); const gen = generationState(id); if (!cancelled && !gen) { return NextResponse.json({ error: "Generation not found." }, { status: 404 }); } return NextResponse.json({ ok: true, state: gen?.state ?? "cancelled" }); }